from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from .forms import SiteUserCreationForm, SiteUserChangeForm
from . import models
from . import utils


class SiteUserAdmin(UserAdmin):
    add_form = SiteUserCreationForm
    form = SiteUserChangeForm
    model = models.SiteUser
    list_display = ('email', 'user_status')
    list_filter = ('email', 'user_status')
    fieldsets = (
        (None, {'fields': ('email', 'password', 'user_status')}),
        #('Permissions', {'fields': ('is_staff', 'is_active')}),
    )
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('email', 'password1', 'password2', 'user_status')}
        ),
    )
    search_fields = ('email',)
    ordering = ('email',)


class AccountAdmin(admin.ModelAdmin):
    list_display = ('id',
                    'additional_information',
                    'data_per_person_with_registration',
                    'link_to_store',
                    'status',
                    'purchase_amount',
                    'payment_date',
                    'track_code',
                    'product_for_display_and_location',
                    'date_of_creation')

    list_display_links = ('id',
                    'additional_information',
                    'data_per_person_with_registration',
                    'link_to_store',
                    'status',
                    'purchase_amount',
                    'payment_date',
                    'track_code',
                    'product_for_display_and_location',
                    'date_of_creation')

    search_fields = ('additional_information', 'data_per_person_with_registration')
    list_filter = ('date_of_creation', 'status', 'purchase_amount') 
    actions = [utils.change_status_to_ban, utils.change_status_to_ok]


utils.change_status_to_ban.short_description = 'Изменить статус аккаунтов на \'Бан\''
utils.change_status_to_ok.short_description = 'Изменить статус аккаунтов на \'OK\''



class AccountAdditionalInformationAdmin(admin.ModelAdmin):
    list_display = ('dolphin_login', 'dolphin_password',
                    'mail_login', 'mail_password')


class TableUserAdmin(admin.ModelAdmin):
    list_display = ('name', 'surname', 'address', 'date_of_birth', 'date_of_creation')


admin.site.register(models.SiteUser, SiteUserAdmin)
admin.site.register(models.Account, AccountAdmin)
admin.site.register(models.AccountAdditionalInformation, AccountAdditionalInformationAdmin)
admin.site.register(models.TableUser, TableUserAdmin) 
